import 'package:intl/intl.dart';

class SmokingRecord {
  final DateTime timestamp;
  
  SmokingRecord({required this.timestamp});
  
  // 将记录转换为可存储的Map
  Map<String, dynamic> toJson() {
    return {
      'timestamp': timestamp.millisecondsSinceEpoch,
    };
  }
  
  // 从Map创建记录
  factory SmokingRecord.fromJson(Map<String, dynamic> json) {
    return SmokingRecord(
      timestamp: DateTime.fromMillisecondsSinceEpoch(json['timestamp']),
    );
  }
  
  // 获取格式化的时间字符串
  String getFormattedTime() {
    return DateFormat('HH:mm').format(timestamp);
  }
  
  // 获取格式化的日期字符串
  String getFormattedDate() {
    return DateFormat('yyyy-MM-dd').format(timestamp);
  }
  
  // 判断是否是同一天
  bool isSameDay(DateTime date) {
    return timestamp.year == date.year && 
           timestamp.month == date.month && 
           timestamp.day == date.day;
  }
} 